/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:31
*/
KISSY.add("toolbar/render",["component/container"],function(i,h){return h("component/container").getDefaultRender().extend({beforeCreateDom:function(f){f.elAttrs.role="toolbar"}})});
KISSY.add("toolbar",["component/container","component/extension/delegate-children","toolbar/render","node"],function(i,h){function f(a,b,c){var c=c.get("children"),d=0,e=c.length;if(void 0===a&&(a=1===b?0:e-1,!c[a].get("disabled")))return c[a];do d++,a=(a+e+b)%e;while(d<e&&c[a].get("disabled"));return d!==e?c[a]:null}function j(a){a.newVal?this.set("expandedItem",null):this.set("expandedItem",a.target)}function k(a){var b=a.target;if(this!==b&&(b.isMenuItem||b.isButton))a.newVal?(a=this.get("children"),
this.get("expandedItem")&&i.inArray(b,a)&&this.set("expandedItem",b.isMenuButton?b:null),this.set("highlightedItem",b)):a.byPassSetToolbarHighlightedItem||this.set("highlightedItem",null)}var l=h("component/container"),m=h("component/extension/delegate-children"),n=h("toolbar/render"),g=h("node").KeyCode;return l.extend([m],{_onSetHighlightedItem:function(a,b){var c,d;c=b&&b.prevVal;d=this.get("children");var e=this.el;c&&i.inArray(c,d)&&c.set("highlighted",!1,{data:{byPassSetToolbarHighlightedItem:1}});
a?(e.ownerDocument.activeElement!==e&&this.focus(),d=a.el,c=d.id,c||(d.id=c=i.guid("ks-toolbar-item")),e.setAttribute("aria-activedescendant",c)):e.setAttribute("aria-activedescendant","")},_onSetExpandedItem:function(a,b){b&&b.prevVal&&b.prevVal.set("collapsed",!0);a&&a.set("collapsed",!1)},bindUI:function(){this.on("afterCollapsedChange",j,this);this.on("afterHighlightedChange",k,this)},handleBlurInternal:function(a){var b;this.callSuper(a);this.set("expandedItem",null);(b=this.get("highlightedItem"))&&
b.set("highlighted",!1)},getNextItemByKeyDown:function(a,b){var c=this.get("children"),c=b&&i.indexOf(b,c);if(b&&b.handleKeyDownInternal(a))return!0;if(a.shiftKey||a.ctrlKey||a.metaKey||a.altKey)return!1;switch(a.keyCode){case g.ESC:return this.view.getKeyEventTarget().fire("blur"),!0;case g.HOME:b=f(void 0,1,this);break;case g.END:b=f(void 0,-1,this);break;case g.UP:b=f(c,-1,this);break;case g.LEFT:b=f(c,-1,this);break;case g.DOWN:b=f(c,1,this);break;case g.RIGHT:b=f(c,1,this);break;default:return!1}return b},
handleKeyDownInternal:function(a){var b;a:{b=this.get("children");var c,d;for(c=0;c<b.length;c++)if(d=b[c],d.get("highlighted")||d.isMenuButton&&!d.get("collapsed")){b=d;break a}b=null}a=this.getNextItemByKeyDown(a,b);if("boolean"===typeof a)return a;a&&a.set("highlighted",!0);return!0}},{xclass:"toolbar",ATTRS:{highlightedItem:{},expandedItem:{},defaultChildCfg:{value:{xclass:"button",handleMouseEvents:!1,focusable:!1}},xrender:{value:n}}})});
